let app = getApp();
var siteinfo = require('../../siteinfo.js');
var amapFile = require('../../utils/amap-wx.js');
Page({
  data: {
    longitude: '',
    latitude: '',
    markers: [],
  },

  onLoad: function (options) {
    this.getList()
    // this.getLocations()
  },

  onShow: function () {

  },
  //获取列表
  getList: function () {
    var _this = this
    app._get(siteinfo.selAboutUs, {
    }, function (result) {
      var longitude = '', latitude = '', markers = [];
      for (var i = 0; i < result.data.aboutUs.length; i++) {
        if (result.data.aboutUs[i].type == 'img') {
          if (result.data.aboutUs[i].value.indexOf(";;") != -1) {//多张图片
            var imgList = result.data.aboutUs[i].value.split(";;");
            result.data.aboutUs[i].value = []
            result.data.aboutUs[i].value = imgList
            result.data.aboutUs[i].moreImg = true
          } else {
            result.data.aboutUs[i].moreImg = false
          }
        }
        if (result.data.aboutUs[i].type == 'longitude') {
          longitude = result.data.aboutUs[i].value
        }
        if (result.data.aboutUs[i].type == 'latitude') {
          latitude = result.data.aboutUs[i].value
        }
      }
      _this.setData({
        list: result.data.aboutUs
      });
      // console.log(' result.data.aboutUs', result.data.aboutUs)
      var info = {}
      info.iconPath = "/image/map.png",
        info.longitude = longitude,
        info.latitude = latitude,
        info.width = 20,
        info.height = 20,
        markers.push(info)
      _this.setData({
        markers: markers,
        latitude: latitude,
        longitude: longitude
      })
    })
  },

  //获取当前经纬度
  // getLocations: function () {
  //   wx.showNavigationBarLoading();
  //   var that = this
  //   wx.getLocation({
  //     type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  //     success: function (res) {
  //       let latitudea = res.latitude
  //       let longitudea = res.longitude
  //       // that.setData({
  //       //   latitude: latitudea,
  //       //   longitude: longitudea,
  //       // })
  //     }
  //   })
  // },
  // regionchange(e) {
  //   console.log(e.type)
  // },
  // markertap(e) {
  //   console.log(e.markerId)
  // },
  // controltap(e) {
  //   console.log(e.controlId)
  // },
  onShareAppMessage: function () {

  }
})